package no.apero.wiiamp;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import no.apero.wiiamp.exceptions.DriveException;

public class GUI {
	public List getFiles(){
		ArrayList<String> list = new ArrayList<String>();
		File[] files = FileReader.getInstance().listFiles();
		if (files!=null){
			for (int i=0; i<files.length; i++){
				list.add(files[i].getName());
			}
		}
		return list;
	}

	public List getDirs(){
		ArrayList<String> list = new ArrayList<String>();
		File[] files = FileReader.getInstance().listDirs();
		if (files!=null){
			for (int i=0; i<files.length; i++){
				list.add(files[i].getName());
			}
		}
		return list;
	}

	public List getDrives(){
		ArrayList<String> list = new ArrayList<String>();
		File[] files = FileReader.getInstance().listDrives();
		for (int i=0; i<files.length; i++){
			String s = files[i].getAbsolutePath();
			list.add(s.substring(0, s.length()-1));
		}
		return list;
	}
	
	public FilePackage getMediaFiles() {
		FilePackage res = new FilePackage();
		ArrayList<String> dirs = new ArrayList<String>();
		ArrayList<String> files = new ArrayList<String>();
		File[] f = FileReader.getInstance().listDirs();
		if (f!=null){
			for (int i=0; i<f.length; i++){
				dirs.add(f[i].getName());
			}
		}
		f = FileReader.getInstance().listMediaFiles();
		if (f!=null){
			for (int i=0; i<f.length; i++){
				files.add(f[i].getName());
			}
		}
		res.setDirs(dirs);
		res.setFiles(files);
		return res;
	}
	
	public FilePackage getClampPathFiles() {
		FilePackage res = new FilePackage();
		ArrayList<String> dirs = new ArrayList<String>();
		ArrayList<String> files = new ArrayList<String>();
		File[] f = FileReader.getInstance().listDirs();
		if (f!=null){
			for (int i=0; i<f.length; i++){
				dirs.add(f[i].getName());
			}
		}
		File a = FileReader.getInstance().listClampFiles();
		if (a!=null){
			files.add(a.getName());
		}
		res.setDirs(dirs);
		res.setFiles(files);
		return res;
		
	}

	public String goInto(String folder) {
		FileReader.getInstance().goInto(folder);
		return "ok";
	}

	public String goUp() {
		try {
			FileReader.getInstance().goUp();
			return "ok";
		} catch (DriveException e) {
			return "drives";
		}
	}

	public String getCurrent() {
		return FileReader.getInstance().getCurrentDir().getAbsolutePath();
	}
	
	public String setClampPath(String path){
		FileReader.getInstance().setClampPath(path);
		return "ok";
	}
	
	public String setDrive(String drive){
		try {
			FileReader.getInstance().setDrive(drive);
		} catch (Exception e) {
			return "ko";
		}
		return "ok";
	}
	
	public String getClampPath(){
		return FileReader.getInstance().getClampPath();
	}
}
